package controller;

import dao.UserDao;
import entity.Permission;
import entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.ResponseBody;
import service.PermissionService;
import service.UserService;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/u")
@Scope("prototype")
public class UserCon {

    @Resource(name="userService")
    private UserService userservice;

    @Resource(name="userDao")
    private UserDao userDao;

    @Resource(name="permissionService")
    private PermissionService permissionService;

    @RequestMapping("/list")
    public String list(Model model){
        model.addAttribute("list",userservice.list());
        return "WEB-INF/jsp/users/userslist";
    }

    @RequestMapping("/li")
    @ResponseBody
    public List<User> li(Model model){
       List<User> jia = userservice.list();

        for(User u:jia){
            System.out.println(u.getName());
        }
        return jia;
    }


    @RequestMapping("/deng")
    @ResponseBody
    public int login(String yhm, String mm){
            User user = new User();
            user.setName(yhm);
            user.setPwd(mm);
            int u = userservice.cha(user);

            return u;


        }

    @RequestMapping("/dome")
    public String ccc(String yhm,String mm,Model model){


        User u = new User();
        u.setName(yhm);
        u.setPwd(mm);

        List<Permission> icon = permissionService.icon(u);
        List<Permission> caidan = permissionService.caidan(u);


        model.addAttribute("icon",icon);
        model.addAttribute("caidan",caidan);




        return "win10-ui/dome";
    }


}
